<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <%- include ../shop/common.ejs%>
    <style>
        .thumb{
            width: 30%;
            /*background-image: url("http://123.57.72.99:3000/images/goods/5881b28b2f6e8730d409a251e83c9a0f.jpg");*/
            background-repeat: no-repeat;
            background-size: cover;
            height: 80px;
            width: 80px;
            margin: 3px;
        }
    </style>
</head>
<body>
<div class="container-fluid">
    <div class="row">
        <div class="col-xs-12" style="padding: 10px 0 10px 15px">
            <a href="/activity/add"><button type="button" class="btn btn-default">新增活动</button></a>&nbsp;&nbsp;
      <!--/goods/edit-->      <a href="#" onclick="getCheckIds()"><button type="button" class="btn btn-default">编辑活动</button></a>&nbsp;&nbsp;
            <button type="button" class="btn btn-default">删除活动</button>
        </div>

        <div class="col-md-12">
            <table class="table table-striped" id="activityTable">
                <thead>
                <tr>
                    <th>√</th>
                    <th>#</th>
                    <th>活动名称</th>
                    <th>预览</th>
                    <th>活动描述</th>
                    <th>活动链接</th>
                    <th>创建时间</th>
                </tr>
                </thead>
                <tbody>
                <%data.rows.forEach(function(activity,index){%>
                <tr>
                    <th><input name="activity_id" type="checkbox" value="<%=activity.id%>"></th>
                    <th scope="row"><%=index+1%></th>
                    <td><div class="thumb" style="background-image: url('<%=activity.thumb%>');"></div></td>
                    <td><%=activity.name%></td>
                    <td><%=activity.description%></td>
                    <td><%=activity.url%></td>
                    <td><%=activity.createtime%></td>

                </tr>
                <%})%>


                </tbody>
            </table>
        </div>
        <div class="col-xs-12">
            <ul id="display-page"></ul>
        </div>
    </div>
</div>
<!--
&lt;!&ndash; 模态框（Modal） &ndash;&gt;
<div class="modal fade" id="myModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close"
                        data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    设置中奖率
                </h4>
            </div>
            <div class="modal-body"  style="width: 700px;">

            </div>
            <div class="modal-footer" style="padding-bottom: 15px;">
                &lt;!&ndash;<button type="button" class="btn btn-default" style="height: 30px;" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" style="margin-bottom: 15px !important;height: 30px;">
                  提交更改
                </button>&ndash;&gt;
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div>&lt;!&ndash; /.modal-content &ndash;&gt;
    </div>&lt;!&ndash; /.modal &ndash;&gt;
</div>

<button class="btn btn-primary"  id="openModal">
    上传图片
</button>-->
</body>
<script>
/*
    $('#openModal').click(function(){
        $('#myModal').modal('toggle');
    });*/
    init(<%= data.total%>);//初始化分页
    function init(total){
        if(total==0){
            total=1;
        }
        var options = {
            currentPage: 1,
            totalPages: parseInt((Number(total)+3-1)/3,10),
            alignment:'center',
            bootstrapMajorVersion:3,
            tooltipTitles: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "跳转到首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "跳转到末页";
                    case "page":
                        return "转到 " + page;
                }
            },
            onPageClicked:function(event, originalEvent, type,page){
                reloadpage(page,false);
            }
        }

        $('#display-page').bootstrapPaginator(options);
    }
    function reloadpage(page,isinit){
        $.get("/activity/list",
                {page:page},
                function(result){
                    if(isinit){
                        init(result.total);
                    }

                    if(result.rows.length<1){
                        $('#rowcontent').html('无数据...');
                        return;
                    }
                    var html = '';
                    result.rows.forEach(function(activity,index){
                        html+='<tr><th><input name="activity_id" type="checkbox" value="'+activity.id+'"></th> <th scope="row">'+(index+1)+'</th>' +
                               '<td><div class="thumb" style="background-image: url(\''+activity.thumb+'\');"></div></td><td>'+activity.name+'</td>'+
                                '<td>'+activity.description+'</td><td>'
                                +activity.url+'</td> <td>'+activity.createtime+'</td></tr>';
                    });
                    $('#activityTable tbody').html(html);
                });
    }


    function getCheckIds(){
        var adIds = "";
        $("input:checkbox[name='activity_id']:checked").each(function(i){
            if(0==i){
                adIds = $(this).val();
            }
        });
        if(!adIds){
            return alert('请选择一件商品!');
        }
        window.location.href="/activity/edit?id="+adIds;
    }
    function getCheckIds1(){
        var adIds = "";
        $("input:checkbox[name='activity_id']:checked").each(function(i){
        if(0==i){
            adIds = $(this).val();
        }else{
            adIds += (","+$(this).val());
        }
//            alert(adIds);
    });

    }
</script>
</html>